<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * FreakAuth_light Class to handle the front controller
 * this class make code more reusable and it makes easier to
 * integrate Freakauth_light in your on templating system
 *
 * The class requires the use of
 *
 * => Database CI official library
 * => Db_session library (included in the download)
 * => FAL_validation library (included in the download)
 * => Freakauth_light library (included in the download)
 * => URL, FORM and FreakAuth_light (included in the download) helpers
 *
 * -----------------------------------------------------------------------------
 * Copyright (C) 2009 TechPundits (tech-pundits.com)
 * -----------------------------------------------------------------------------
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *------------------------------------------------------------------------------
 * @package     care and comfort 2009-09-18
 * @subpackage  Libraries
 * @category    Authentication
 * @author      pradeep kumar
 * @copyright   Copyright (c) 2009,TechPundits (tech-pundits.com)
 * @license		http://www.gnu.org/licenses/lgpl.html
 * @link 		http://tech-pundits.com
 * 
 *
 */

class CNC_orders{
	
	public $base_uri ;
	function CNC_orders()
	{
		
		$this->CI = &get_instance();
		$this->base_uri = site_url().$this->CI->uri->slash_segment(1,'both').$this->CI->uri->slash_segment(2).$this->CI->uri->segment(3);
		//loads necessary libraries
        $this->CI->lang->load('freakauth');
        if (!class_exists('CI_Validation'))
		{
		     $this->CI->load->library('validation');
		}
		//let's load the FAL_validation library if it isn't already loaded
		if (!class_exists('FAL_validation'))
		{
		     $this->CI->load->library('FAL_validation');
		}
		
		//let's load the Freakauth_light library if it isn't already loaded
		//or autoloaded
		if (!class_exists('Freakauth_light'))
		{
		     $this->CI->load->library('Freakauth_light', 'freakauth_light');
		}
       
		//let's check if we have core classes extensions, and if we have them
		//let's load them
    	if ($this->CI->config->item('FAL_use_extensions'))
    	{
    	    $this->_loadExtensions();
    	}
    	else
    	{
    	    log_message('debug', 'FAL not using extensions');
    	}
       
		$this->CI->fal_validation->set_error_delimiters($this->CI->config->item('FAL_error_delimiter_open'), $this->CI->config->item('FAL_error_delimiter_close'));
		$this->_prefix = $this->CI->config->item('FAL_table_prefix');
        $this->_table = $this->_prefix.'grocery_order';
//        $this->_container = $this->CI->config->item('FAL_template_dir').'template_admin/order_table';       
	}
	
	 // --------------------------------------------------------------------
    /**
     * FAL extensions handler.
     * It makes easier to load extensions to the classes in 
     * (libraries/FreakAuth_light.php) or the FAL_validation.php class build
     *  your files according to the following specifications about file-names.
     *  You can place them either in system/libraries or in application/libraries
     * 
     * - libraries/MyFAL.php
     * - libraries/MyFALVal.php
     * 
     * Following this convention, if $config['FAL_use_extensions'] = TRUE;
     * the above files will be loaded 
     */
    function _loadExtensions()
    {
  
        if (file_exists(APPPATH.'libraries/MyFAL'.EXT) OR file_exists(BASEPATH.'libraries/MyFAL'.EXT))
        {
            //let's load the core library (i.e. FreakAuth_light.php) extension
            $this->CI->load->library('MyFAL');
            
            $this->CI->freakauth_light = new MyFAL();
            log_message('debug', 'MyFAL library loaded');
            log_message('debug', 'MyFAL class assigned to $this->CI->freakauth_light');
        }
        else
        {
            log_message('debug', 'MyFAL class not found');
        }

        if (file_exists(APPPATH.'libraries/MyFALVal'.EXT) OR file_exists(BASEPATH.'libraries/MyFALVal'.EXT))
        {
            //let's load the validation library (i.e. FAL_validation.php) extension
            //and assign it to $this->CI->fal_validation
            $this->CI->load->library('MyFALVal');
            $this->CI->fal_validation = new MyFALVal();

        }
        else
        {
            log_message('debug', 'MyFALVal class not found');
        }
    }
    
    function get_orders($type)
    {
    	$this->CI->load->library('pagination');
    	$config['base_url'] = $this->base_uri;
    	$config['uri_segment'] = 4;
    	$config['per_page'] = $this->CI->config->item('FAL_admin_console_records_per_page');
		$config['full_tag_open'] = '<p>';
		$config['full_tag_close'] = '</p>';
		$config['cur_tag_open'] = '<b>';
		$config['cur_tag_close'] = '</b>';
		$config['next_link'] = '&gt ';
		$config['prev_link'] = ' &lt ';
		$config['last_link'] = ' Last &raquo; ';
		$config['first_link'] = ' &laquo; First ';
		$limit = $config['per_page'];
		$query = $this->CI->orders_model->get_order_details($type,null,null);
		$config['total_rows'] = $query->num_rows();
    	$this->CI->pagination->initialize($config);		
    	$offset = $this->CI->uri->segment(4, 0);
		$pagenation = $this->CI->pagination->create_links();
		$this->CI->load->model('Orders_model','order_model');
		$order_res = $this->CI->order_model->get_order_details($type,$limit,$offset);
		 
        $data = array(
        				'query' => 	$order_res,
        				'pagenation_links' => $pagenation,
        				
        				);
		return $this->CI->load->view($this->CI->config->item('CNC_admin_order_table'), $data, TRUE);
    }
    function get_grocery_orders()
    {
    	
    }
      
    
}?>